package com.sk.cardeal.act.home.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.sk.cardeal.R;
import com.sk.cardeal.act.home.fragment.TodayMessageFragment;
import com.sk.cardeal.adapter.MyPagerAdapter;
import com.sk.cardeal.base.BaseActivity;
import com.sk.cardeal.callback.HandleDataCallBack;
import com.sk.cardeal.entity.TodayCountBean;
import com.sk.cardeal.utils.AppApi;
import com.sk.cardeal.view.TitleView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by sk on 2017/12/18.
 */

public class MessageBoardActivity extends BaseActivity implements HandleDataCallBack {
    @BindView(R.id.title_view)
    TitleView titleView;
    @BindView(R.id.in_num)
    TextView inNum;
    @BindView(R.id.fix_num)
    TextView fixNum;
    @BindView(R.id.already_num)
    TextView alreadyNum;
    @BindView(R.id.my_pager)
    ViewPager myPager;
    List<Fragment> fragments = new ArrayList<>();

    @Override
    protected int getContentView() {
        return R.layout.activity_message_board;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        titleView.setMyCallBack(this);
        AppApi.getToadyData(this, 0, this);
        initFragments();
    }

    private void initFragments() {
        TodayMessageFragment todayMessageFragment1 = TodayMessageFragment.newInstance(0);
        fragments.add(todayMessageFragment1);

        TodayMessageFragment todayMessageFragment2 = TodayMessageFragment.newInstance(2);
        fragments.add(todayMessageFragment2);

        TodayMessageFragment todayMessageFragment3 = TodayMessageFragment.newInstance(1);
        fragments.add(todayMessageFragment3);

        myPager.setOffscreenPageLimit(3);

        MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager(), getResources().getStringArray(R.array.today_array), fragments);
        myPager.setAdapter(adapter);
    }


    @Override
    public void clickTitle(int i) {
        super.clickTitle(i);
        switch (i) {
            case 1:
                finish();
                break;
            case 2:
                break;
            case 3:
                break;
        }
    }

    @Override
    public void handlerSuccessData(String result, int tag) {
        TodayCountBean todayCountBean = JSON.parseObject(result, TodayCountBean.class);
        inNum.setText(todayCountBean.getReturnObject().getAllCount()+"");
        fixNum.setText(todayCountBean.getReturnObject().getWaitCount()+"");
        alreadyNum.setText(todayCountBean.getReturnObject().getCompleteCount()+"");
    }

    @Override
    public void handlerFailData(String failString, int tag) {

    }

    @Override
    public void handleErrorData(String error, int tag) {

    }

    @OnClick({R.id.ll_1, R.id.ll_2, R.id.ll_3})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_1:
                myPager.setCurrentItem(0);
                break;
            case R.id.ll_2:
                myPager.setCurrentItem(1);
                break;
            case R.id.ll_3:
                myPager.setCurrentItem(2);
                break;
        }
    }
}
